package com.yanggu.scala.chapater12.list

//模式匹配-匹配列表
object MatchListDemo01 {

  def main(args: Array[String]): Unit = {
    //列表中的元素使用 :: 来枚举
    for (list <- Array(List(0), List(1, 0), List(0, 0, 0), List(1, 0, 0))) {
      val result = list match {
        case 0 :: Nil => "start with 0"
        case x :: y :: Nil => s"only start with $x and $y"
        case x :: y :: _ => s"start with $x and $y and others"
        case 0 :: _ => s"start with 0 and others"
        case _ => "Something else"
      }
      println(result)
    }
  }

}
